/**
 * Created with JetBrains WebStorm.
 * User: a_polyakov
 * Date: 08.03.13
 * Time: 18:00
 * To change this template use File | Settings | File Templates.
 */
exports.getFileName = function (fileName) {
    fileName = fileName.trim().toLowerCase();
    var result = '';
    for (var i = 0; i < fileName.length; i++) {
        var c = fileName[i];
        if (c <= ' ' || c == '\"' || c == '*' || c == '/' || c == ':' || c == '<' || c == '>' || c == '?' || c == '\\' || c == '`' || c == '|'
            || c == '#' // баг с url вида http://localhost:3000/montserrat/plymouth/poste_italiane___#9066
            || c == '-' // разделитель между именем и номером страницы
            || c == '.' || c == ',' || c=='\'' || c=='!' || c=='~' || c=='@' || c=='$' || c=='%' || c=='(' || c==')' || c=='+' || c=='=' || c=='{' || c=='}' || c==';'
            ) {
            result += '_';
        } else {
            result += c;
        }
    }
    result=result.replace(new RegExp('_{2,}','g'), '_');
    return result;
}
